package com.geovis.emergency.spd.controller.filing;

import cn.hutool.core.util.StrUtil;
import com.geovis.common.core.api.Result;
import com.geovis.common.core.constant.SwaggerConstants;
import com.geovis.emergency.spd.biz.filing.service.ITbPlanFilingsService;
import com.geovis.emergency.spd.biz.system.service.ISystemFileService;
import com.geovis.emergency.spd.cache.DictCache;
import com.geovis.emergency.spd.entity.filing.entity.TbPlanFilings;
import com.geovis.emergency.spd.entity.mobile.pojo.vo.SignMobileConfigVO;
import com.geovis.emergency.spd.entity.pc.pojo.constant.PcDisasterConstant;
import com.geovis.emergency.spd.entity.pc.pojo.vo.PcPlanDetailVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/filing")
@RequiredArgsConstructor
@Api(value = "预案备案接口", tags = "预案备案接口")
@Slf4j
public class FilingController {

    private final ITbPlanFilingsService tbPlanFilingsService;

    private final ISystemFileService systemFileService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取预案备案列表", notes = "获取预案备案列表")
    @GetMapping("/getList")
    public Result<List<TbPlanFilings>> getList() {
        return Result.ok(tbPlanFilingsService.getList());
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "获取预案备案详情", notes = "获取预案备案详情")
    @PostMapping("/getDetail")
    public Result<PcPlanDetailVO> getDetail(@ApiParam(value="预案备案系统的预案id",name="filingPlanId") String filingPlanId) {

        PcPlanDetailVO detailVO=tbPlanFilingsService.getDetail(filingPlanId);
        //tbPlanFilingsService的数据源和主数据源不同，所以这里eventName的处理暂时放出来
        String dictValue = DictCache.getDictValue(PcDisasterConstant.DISASTER_TYPE, detailVO.getType());
        detailVO.setTypeName(dictValue);
        systemFileService.saveFromFiling(detailVO);
        return Result.ok(detailVO);
    }

}
